<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
import '../../../node_modules/echarts/map/js/china.js'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '400px'
    },
    dataJson: Array
  },
  data() {
    return {
      chart: null,
    }
  },
  watch: {
    dataJson(newval, oldval) {
      this.dataJson = newval
      this.initChart()
    }
  },
  mounted() {
    setTimeout(()=>{
      this.initChart()
    }, 500)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        title: {
          text: '全国订单分布统计',
          subtext: '统计已完成订单的总金额',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        dataRange: {
          orient: 'horizontal',
          min: 0,
          max: 55000,
          text:['高','低'],           // 文本，默认为数值文本
          inRange: {
            color: ['#f5eeae', '#b24c4f']
          },
          splitNumber:0
        },
        series: [{
          name: '全国订单分布统计',
          type: 'map',
          mapType: 'china',
          zoom: '1.2',
          roam: false,
          label: {
            normal: {
                show: true  //省份名称
            },
            emphasis: {
                show: false
            }
          },
          mapLocation: {
              x: 'center'
          },
          selectedMode : 'multiple',
          itemStyle:{
              normal:{label:{show:true}},
              emphasis:{label:{show:true}}
          },
          data: this.dataJson,
          animationDuration: animationDuration
        }]
      })
    }
  }
}
</script>
